/*
 * Created on Sep 10, 2003
 *
 * GroupRole
 * Local Projects Database
 * (c) 2003 eRomania Gateway Association
 *
 */
package ro.gateway.aida.usr;

import java.util.Comparator;
import java.util.Vector;



/**
 * @author Mihai Postelnicu
 *
 * This is the GroupRole type definition
 *
 */
public abstract class GroupRole
{

      public static class GroupRoleComparator implements Comparator
      {
            public int compare( Object o1, Object o2 )
            {
                  GroupRole u1 = ( GroupRole ) o1;
                  GroupRole u2 = ( GroupRole ) o2;
                  return ( u1.getId() - u2.getId() );
            }
      }

      protected String name;
      protected String description;
      protected int id;

      public GroupRole( String name, String description )
      {
            this.name = name;
            this.description = description;
      }

      public static Vector createAllRoles()
      {
            Vector returned = new Vector();

            for ( int i = 1; i <= role_count; i++ )
                  returned.add( createRole( i ) );

            return returned;
      }

      public static GroupRole createRole( int role_id )
      {
            switch ( role_id )
            {
                  case REGISTERED_ROLE:
                        return new RegisteredRole();

                  case EDITOR_ROLE:
                        return new EditorRole();

                  case APPROVER_ROLE:
                        return new ApproverRole();

                  case ADMINISTRATOR_ROLE:
                        return new AdministratorRole();

                  default:
                        return new GuestRole();
            }
      }

      //implement this to define the Role permissions
      public abstract boolean canDo( int permission );

      /**
       * @return
       */
      public String getDescription()
      {
            return description;
      }

      /**
       * @return
       */
      public int getId()
      {
            return id;
      }

      /**
       * @return
       */
      public String getName()
      {
            return name;
      }

      /**
       * @param string
       */
      public void setDescription( String string )
      {
            description = string;
      }

      /**
       * @param i
       */
      public void setId( int i )
      {
            id = i;
      }

      /**
       * @param string
       */
      public void setName( String string )
      {
            name = string;
      }

      public static final int GUEST_ROLE = 1;
      public static final int REGISTERED_ROLE = 2;
      public static final int EDITOR_ROLE = 3;
      public static final int APPROVER_ROLE = 4;
      public static final int ADMINISTRATOR_ROLE = 5;
      public static final int role_count = 5;
	  public static final String CURRENT = "current user's role";
}
